<!DOCTYPE html>

<html lang="zh-Hans">
  <head>
    <meta charset="utf-8" />
    <meta name="author" content="rogepi" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="/vue.global.js"></script>
    <title>1-computed-basic</title>
  </head>

  <body>
    <div id="computed-basic">
      <p>Has published books:</p>
      <span>{{publishedBooksMessage}}</span>
    </div>
    <script>
      const vm = Vue.createApp({
        data() {
          return {
            author: {
              name: 'John Doe',
              books: [
                'Vue 2 - Advanced Guide',
                'Vue 3 - Basic Guide',
                'Vue 4 - The Mystery',
              ],
            },
          };
        },
        // 对于任何包含响应式数据的复杂逻辑，都应该使用计算属性
        computed: {
          publishedBooksMessage() {
            return this.author.books.length > 0 ? 'Yes' : 'No';
          },
        },
      }).mount('#computed-basic');
    </script>
  </body>
</html>
